package com.mc.lp.database.entity.type;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * class names enum
 * 
 * @author deepak
 */
public enum SchoolGrade {
	DEFAULT("Not Used", 0), NURSERY("Nursery", 1), KG("KG", 2), LKG("LKG", 3), 
	CLASS_1ST("1st", 4), CLASS_2ND("2nd", 5), CLASS_3RD("3rd", 6), CLASS_4TH("4th", 7),
	CLASS_5TH("5th", 8), CLASS_6TH("6th", 9), CLASS_7TH("7th", 10), CLASS_8TH("8th", 11), 
	CLASS_9TH("9th", 12), CLASS_10TH("10th", 13), CLASS_11TH("11th", 14), CLASS_12TH("12th", 15);

	private SchoolGrade(String value, Integer id) {
		this.value = value;
		this.id = id;
	}

	String value;
	Integer id;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public static SchoolGrade getSchoolGrade(Integer id){
		
		if (id == null) {
            return null;
        }
 
        for (SchoolGrade schoolGrade : SchoolGrade.values()) {
            if (id.equals(schoolGrade.getId())) {
                return schoolGrade;
            }
        }
        throw new IllegalArgumentException("No matching type for id " + id);
	}
	
	public static String getSchoolGradeName(Integer id){
		
		if (id == null) {
            return null;
        }
 
        for (SchoolGrade schoolGrade : SchoolGrade.values()) {
            if (id.equals(schoolGrade.getId())) {
                return schoolGrade.getValue();
            }
        }
        throw new IllegalArgumentException("No matching type for id " + id);
	}

	@Converter(autoApply = true)
	class SchoolGradeConverter implements AttributeConverter<SchoolGrade, String> {

		public String convertToDatabaseColumn(SchoolGrade termType) {
			return String.valueOf(termType.ordinal());
		}

		public SchoolGrade convertToEntityAttribute(String dbData) {
			return SchoolGrade.valueOf(dbData);
		}
	}
}